# !/usr/bin/env python
# -*-coding:utf-8 -*-

"""
# File       : auto_arrive_time.py
# Time       ：2021/8/21 13:19
# Author     ：王洪磊
# Email      ： wang_hl007@163.com
# Description：自动标波程序
"""

import h5py
import numpy as np
import pandas as pd
from pathlib2 import Path
from tqdm import tqdm

import warnings


def auto_pat(data: pd.DataFrame):
    # TODO 返回p波到时
    wave_data = data
    sk = wave_data.rolling(100).skew()
    arrive_time = sk.idxmax()

    return arrive_time.values[0]


def auto_sat(data: pd.DataFrame):
    # TODO S波首时定位
    wave_data = data
    sk = wave_data.rolling(100).skew()
    arrive_time = sk.idxmax()

    return arrive_time.values[0]+0.3


def auto_sot(data: pd.DataFrame):
    # TODO S波末时定位
    wave_data = data
    sk = wave_data.rolling(100).skew()
    arrive_time = sk.idxmax()

    return arrive_time.values[0]+2.8


def auto_pot(data: pd.DataFrame):
    # TODO P波末时定位
    wave_data = data
    sk = wave_data.rolling(100).skew()
    arrive_time = sk.idxmax()
    return arrive_time.values[0]+2


def locate(wave_data):
    x = None
    y = None
    z = None
    return x, y, z


def wave_energy(wave_data):
    energy = None
    return energy

def main():
    import matplotlib.pyplot as plt
    from utils.read_wav_raw import read_ms
    path_bin = r'D:\云空间\git\微震分析系统\resource\sos波形\A01_180803_140014465.bin'
    raw_data = read_ms(path_bin)
    raw_data['time'] = raw_data.index / 500
    data = raw_data[['time', 't2']]
    data = data.set_index('time')
    plt.plot(data)
